package com.ypx.practice;


import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class TreeSetPractice {
    public static void main(String[] args) {
        TreeSet<Person> ts = new TreeSet<>(new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return (int)(o2.getChinese() + o2.getMath() + o2.getEnglish() - (o1.getChinese() + o1.getMath() + o1.getEnglish()));
            }
        });
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入第" + (i + 1) + "个学生信息");
            System.out.print("姓名：");
            //不能有空格
            String name = scanner.next();//线程阻塞，等待输入
            System.out.print("语文：");
            double chinese = scanner.nextDouble();
            System.out.print("数学：");
            double math = scanner.nextDouble();
            System.out.print("英语：");
            double english = scanner.nextDouble();
            Person person = new Person(name, chinese, math, english);
            ts.add(person);

        }
        System.out.println("学生信息如下：");
        for (Person person : ts) {
            System.out.println(person);
        }
    }


}

